/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-9-13
 * Time: 下午6:41
 * To change this template use File | Settings | File Templates.
 */

var DHD_URL = "/kcgl/dhd/rksh_dhd_content?cgdmxId={0}";

function dhdUpCell(val, row) {
    return formatterUpCell(val, "DHD_URL", row.id);
}

function formatterUpCell(val, url, params) {
    var b = "javascript:dhd_showDialog('{0}','{1}');".stringFormat(url, params);
    var a = "javascript:dhd_showUpDialog('{0}','{1}');".stringFormat(url, params);
    var c = "javascript:dhd_showDektialDialog('{0}');".stringFormat(params);
    if (!val || val == '0') {
        return '<a href="' + b + '" style="color: red;text-decoration:underline">' + '编辑到货单' + '</a>';
    } else if (val == '1') {
        return '<a href="' + a + '" style="color: red;text-decoration:underline">' + '保管员已保存' + '</a>';
    } else if (val == '2') {
        return '<a href="' + a + '" style="color: red;text-decoration:underline">' + '保管员已提交' + '</a>';
    } else if (val == '3') {
        return '<a href="' + a + '" style="color: red;text-decoration:underline">' + '验收员已保存' + '</a>';
    } else if (val == '4') {
        return '<a href="' + c + '" style="color: blue;text-decoration:underline">' + '验收员已验收' + '</a>';
    }
}


//新增弹出窗口
function dhd_showDialog(url, params) {
    var urlChange;
    if ($('#zt').val()) {
        urlChange = $.webPath() + "/kcgl/dhd/update_dhd";
    } else {
        urlChange = $.webPath() + "/kcgl/dhd/add_dhd";
    }
    var win = $.window({
        title:'到货单编辑',
        width:900,
        height:500,
        cache:false,
        url:$.webPath() + eval(url).stringFormat(params.split(",")),
        modal:true,
        buttons:[
            {
                text:'提交',
                handler:function () {
                    $(win).mask();
                    $('#dhd_Form').form('submit', {
                        url:urlChange,
                        onSubmit:function () {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $(win).mask('hide');
                                return false;
                            }
                            $("#zt").val((parseFloat($("#zt").val()) + 1).toString());
                            return isValid;
                        },
                        success:function (data) {
                            $(win).mask('hide');
                            var json = $.parseJSON(data);
                            if (json.statusCode == 200) {
                                $(win).window('close');
                                $('#rksh_ys_mx').datagrid('reload');
                                $('#rksh_zcrk_mx').datagrid('reload');
                                $('#cgd_cgdmx_table').datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:json.message,
                                    timeout:3000,
                                    showType:'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            },
            {
                text:'保存',
                handler:function () {
                    $(win).mask();
                    $('#dhd_Form').form('submit', {
                        url:$.webPath() + "/kcgl/dhd/add_dhd",
                        onSubmit:function () {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $(win).mask('hide');
                                return false;
                            }
                            return isValid;
                        },
                        success:function (data) {
                            $(win).mask('hide');
                            var json = $.parseJSON(data);
                            if (json.statusCode == 200) {
                                $(win).window('close');
                                $('#rksh_ys_mx').datagrid('reload');
                                $('#rksh_zcrk_mx').datagrid('reload');
                                $('#cgd_cgdmx_table').datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:json.message,
                                    timeout:3000,
                                    showType:'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            }
        ]
    });
}
//修改弹出窗口
function dhd_showUpDialog(url, params) {
    var win = $.window({
        title:'到货单编辑',
        width:900,
        height:500,
        cache:false,
        url:$.webPath() + eval(url).stringFormat(params.split(",")),
        modal:true,
        buttons:[
            {
                text:'提交',
                handler:function () {
                    $(win).mask();
                    $('#dhd_Form').form('submit', {
                        url:$.webPath() + "/kcgl/dhd/update_dhd",
                        onSubmit:function () {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $(win).mask('hide');
                                return false;
                            }
                            $("#zt").val((parseFloat($("#zt").val()) + 1).toString());
                            return isValid;
                        },
                        success:function (data) {
                            $(win).mask('hide');
                            var json = $.parseJSON(data);
                            if (json.statusCode == 200) {
                                $(win).window('close');
                                $('#rksh_ys_mx').datagrid('reload');
                                $('#rksh_zcrk_mx').datagrid('reload');
                                $('#cgd_cgdmx_table').datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:json.message,
                                    timeout:3000,
                                    showType:'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            },
            {
                text:'保存',
                handler:function () {
                    $(win).mask();
                    $('#dhd_Form').form('submit', {
                        url:$.webPath() + "/kcgl/dhd/update_dhd",
                        onSubmit:function () {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $(win).mask('hide');
                                return false;
                            }
                            return isValid;
                        },
                        success:function (data) {
                            $(win).mask('hide');
                            var json = $.parseJSON(data);
                            if (json.statusCode == 200) {
                                $(win).window('close');
                                $('#rksh_ys_mx').datagrid('reload');
                                $('#rksh_zcrk_mx').datagrid('reload');
                                $('#cgd_cgdmx_table').datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:json.message,
                                    timeout:3000,
                                    showType:'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            }
        ]
    });
}

//明细弹出窗口
function dhd_showDektialDialog(params) {
    var win = $.window({
        title:'到货单查看',
        width:900,
        height:500,
        cache:false,
        url:$.webPath() + "/kcgl/dhd/rksh_dhd_detail?cgdmxId=" + params,
        modal:true
    });
}
